<?php
namespace app\index\service;

use app\index\model\CityModel;
use app\index\model\DeptModel;
use app\index\model\FileModel;
use app\index\model\FlowBillModel;
use app\index\model\FlowLogModel;
use app\index\model\FlowNodeModel;
use app\index\model\FlowShenlogModel;
use app\index\model\LogListModel;
use app\index\model\OptionModel;
use app\index\model\TodoModel;
use app\index\model\UserModel;
use app\index\model\WorkerModel;
use app\index\worker\Worker;

class WorkerService extends CommonService
{
    public function add_worker_todo($uid=0, $title='', $mess='', $mid=0, $table='', $meter=''){
//        $title = '消息提醒-'.$title;
        $title = '消息提醒';
        return $this->add_worker('todo', $uid, $title, $mess, $mid, $table, $meter);
    }

    public function add_worker_bidwork($uid=0, $mess='', $mid=0, $table='', $meter=''){
        return true;
    }


    public function add_worker_task($uid=0, $mess='', $mid=0, $table='', $meter=''){
        $title = '任务提醒';
        return $this->add_worker('task', $uid, $title, $mess, $mid, $table, $meter);
    }


    public function add_worker_bill($uid=0, $type='', $bill){
//        $title = '待办提醒-'.$bill['modename'];
        $title = '待办提醒';
        $mess = "";

        if($type == 'shen'){
            $mess = "待我处理：[".$bill['created_user_name']."]发起的[".$bill['modename']."]";
        }

        if($type == 'tui'){
//            $mess = "待我处理：[".$bill['created_user_name']."]退回给我的[".$bill['modename']."]";
            $mess = "待我处理：[".$this->userinfo['realname']."]退回给我的[".$bill['modename']."]";
        }

        if($type == 'add'){
//            $mess = "待我处理：[".$bill['created_user_name']."]加签给我的[".$bill['modename']."]";
            $mess = "待我处理：[".$this->userinfo['realname']."]加签给我的[".$bill['modename']."]";
        }

        if($type == 'zhuan'){
//            $mess = "待我处理：[".$bill['created_user_name']."]转签给我的[".$bill['modename']."]";
            $mess = "待我处理：[".$this->userinfo['realname']."]转签给我的[".$bill['modename']."]";
        }

        if($type == 'urge'){
//            $mess = "待我处理：[".$bill['created_user_name']."]发起的[".$bill['modename']."]";
            $mess = $bill['summary'].",请及时处理。";
        }

        return $this->add_worker('bill', $uid, $title, $mess, $bill['mid'], $bill['modenum']);
    }

    public function add_worker_email($uid=0, $mess='', $mid=0, $table='', $meter=''){
//        $title = '邮件提醒-新邮件';
        $title = '邮件提醒';
        return $this->add_worker('email', $uid, $title, $mess, $mid, $table, $meter);
    }

    public function add_worker($uid, $title, $enginname, $mid=0, $table='', $meter=''){

        $mess = '待我处理：【'.$enginname.'】的'.$title;

        $ins = [];
        $ins['type'] = 'bill';
        $ins['uid'] = $uid;
        $ins['title'] = '待办提醒-'.$title;
        $ins['mess'] = $mess;
        $ins['mid'] = $mid;
        $ins['table'] = $table;
        $ins['meter'] = $meter;
        $ins['dt'] = date("Y-m-d H:i:s");
        return WorkerModel::insert($ins);
    }


}
